package com.east.controller.sale;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.east.bean.Contract;
import com.east.service.sale.ContractService;
import com.east.utils.PageJson;
import com.east.utils.Pagenation;
import com.east.utils.Result;
import com.east.utils.ResultUtil;
import com.github.pagehelper.Page;
/**
 * 采购合同
 * @author Administrator
 *
 */
@RestController
@RequestMapping("sale")
public class ContractController {
	@Autowired
	ContractService contractService;
	
	/**
	 * 全查
	 * 分页
	 * @param pagenation
	 * @param key
	 * @return
	 */
	@GetMapping("all")
	@RequiresPermissions("sale:all")
	public Result findByPage(Pagenation pagenation,String key,String startTime ,String endTime) {
		Page<Contract> findByPage = contractService.findByPage(pagenation, key,26,startTime,endTime);
		Object pageJson = new PageJson<Contract>().pageJson(findByPage);
		return ResultUtil.success(pageJson);
	}
	/**
	 * 详情
	 * @param fee
	 * @return
	 */
	@GetMapping("findOne")
	@RequiresPermissions("sale:findOne")
	public Result findByfindOne(Contract contract) {
		Contract findByProjectId = contractService.findByOne(contract);
		return ResultUtil.success(findByProjectId);
	}
	/**
	 * 编号是否存在
	 * @param fee
	 * @return
	 */
	@GetMapping("findlike")
	@RequiresPermissions("sale:findlike")
	public Result findByfindLike(Contract contract) {
		int findByProjectId = contractService.findByLike(contract);
		return ResultUtil.success(findByProjectId);
	}
	
	/**
	 * 添加
	 * @param fee
	 * @return
	 */
	@PostMapping("add")
	@RequiresPermissions("sale:add")
	public Result findByAdd(Contract contract) {
		  boolean saveProject = contractService.saveContract(contract);
		  if(saveProject) {
			  return ResultUtil.success("保存成功");
		  }else {
			  return ResultUtil.success("保存失败");
		  }
		
	}
	/**
	 * 修改
	 * @param fee
	 * @return
	 */
	@PostMapping("update")
	@RequiresPermissions("sale:update")
	public Result findByUpdate(Contract contract) {
		  boolean updateProject = contractService.updateContract(contract);
		  if(updateProject) {
			  return ResultUtil.success("修改成功");
		  }else {
			  return ResultUtil.success("修改失败");
		  }
	}
	/**
	 * 删除
	 * @param fee
	 * @return
	 */
	@DeleteMapping("del")
	@RequiresPermissions("sale:del")
	public Result findByDel(Contract contract) {
		 boolean findByProjectId = contractService.delContract(contract);
		 if(findByProjectId) {
			  return ResultUtil.success("删除成功");
		 }else {
				  return ResultUtil.success("删除失败");
		 }
	}
}
